<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">

	<ui:define name="corpoForm">
		

		<h:form id="formBotoesPermissao" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarPermissao" value="#{rsc.label_criar}"
					rendered="#{p:ifGranted('CRIAR_PERMISSAO')}" styleClass="botao"
					action="#{manterPermissaoBean.criarEntidade}" ajax="false"
					title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterPermissaoBean.preRenderList}" />
		<h:form id="formListPermissoes" prependId="false">

			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">
				<p:panelGrid columns="5">

					<p:outputLabel value="#{rsc.label_permissao} " for="acPermissao" />

					<p:outputLabel value="#{rsc.label_role} " for="txtRolePermissao" />

					<p:outputLabel value="#{rsc.label_urlPermissao} " for="txtUrlPermissao" />

					<p:outputLabel value="#{rsc.label_ativo}" for="cmbAtivo" />

					<p:spacer />

					<p:autoComplete id="acPermissao" minQueryLength="3" size="44"
						value="#{manterPermissaoBean.filtro.nome}" effect="fade"
						maxResults="7"
						completeMethod="#{manterPermissaoBean.autoCompleteNome}">
						<p:ajax event="change"
							listener="#{manterPermissaoBean.buscarPorFiltros}"
							update="listPermissoes" />
					</p:autoComplete>

					<p:inputText label="#{rsc.label_role}" id="txtRolePermissao"
						maxlength="60" size="20" title="#{rsc.label_role}"
						value="#{manterPermissaoBean.filtro.role}">
						<p:ajax event="change"
							listener="#{manterPermissaoBean.buscarPorFiltros}"
							update="listPermissoes" />
					</p:inputText>

					<p:inputText label="#{rsc.label_urlPermissao}" id="txtUrlPermissao"
						maxlength="60" size="20" title="#{rsc.label_urlPermissao}"
						value="#{manterPermissaoBean.filtro.url}">
						<p:ajax event="change"
							listener="#{manterPermissaoBean.buscarPorFiltros}"
							update="listPermissoes" />
					</p:inputText>

					<p:selectOneMenu label="#{rsc.label_ativo}"
						value="#{manterPermissaoBean.filtro.ativo}" id="cmbAtivo">
						<p:ajax event="change"
							listener="#{manterPermissaoBean.buscarPorFiltros}"
							update="listPermissoes" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterPermissaoBean.status}" var="c"
							itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:commandButton update="listPermissoes"
						actionListener="#{manterPermissaoBean.buscarPorFiltros}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />
				</p:panelGrid>
			</p:fieldset>
			<p:watermark value="#{rsc.wm_nomePermissaoConsulta}"
				for="acPermissao" />


			<p:panel id="pnlInfo" header="#{rsc.label_permissoesCadastradas}"
				toggleable="true" toggleSpeed="500">
				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="permissao" id="listPermissoes"
						value="#{manterPermissaoBean.entidades}" paginator="true"
						rows="10" paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">
						<p:column headerText="#{rsc.label_nomePermissao}">
							<p:outputLabel value="#{permissao.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_urlPermissao}">
							<p:outputLabel value="#{permissao.url}" />
						</p:column>

						<p:column headerText="#{rsc.label_funcionalidade}">
							<p:outputLabel value="#{permissao.funcionalidade.nome}" />
						</p:column>

						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">
							<p:commandButton update=":permissaoData"
								oncomplete="detalhar.show();" icon="ui-icon ui-icon-search"
								title="#{rsc.label_detalhar}">
								<f:setPropertyActionListener value="#{permissao}"
									target="#{manterPermissaoBean.entidade}" />
							</p:commandButton>

							<p:commandButton icon="ui-icon ui-icon-pencil"
								title="#{rsc.label_editar}" ajax="false"
								action="editarPermissao"
								rendered="#{p:ifGranted('ALTERAR_PERMISSAO')}">
								<f:setPropertyActionListener value="#{permissao}"
									target="#{manterPermissaoBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>
		</h:form>

		<p:dialog id="detalharDialog" header="#{rsc.label_detalhar}"
			widgetVar="detalhar" width="520">
			<p:panelGrid columns="2" cellspacing="4" id="permissaoData">
				<p:outputLabel value="#{rsc.label_nomePermissao}:"
					style="font-weight: bold;" />
				<p:outputLabel value="#{manterPermissaoBean.entidade.nome}" />
				<p:outputLabel value="#{rsc.label_urlPermissao}:"
					style="font-weight: bold;" />
				<p:outputLabel value="#{manterPermissaoBean.entidade.url}" />
			</p:panelGrid>
		</p:dialog>


	</ui:define>
</ui:composition>

